home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.c++
- Path: uu4news.netcom.com!friend!news
- From: rich@kastle.com (Richard Krehbiel)
- Subject: Re: sizeof() question >>> :)
- Message-ID: <1996Apr15.113552.27625@friend.kastle.com>
- Sender: news@friend.kastle.com (News)
- Reply-To: rich@kastle.com
- Organization: Kastle Development Associates
- X-Newsreader: Forte Free Agent 1.0.82
- References: <1996Apr12.061927@topaz>
- Date: Mon, 15 Apr 1996 11:37:40 GMT
-
- naderr@topaz.cqu.edu.au wrote:
-
- >Hi,
-
- >How can I get, with a pointer, the sizeof of an array that is
- >pointed by the pointer ? (No it's not a tounge twister :)
-
- This information is simply not available if all you have is a pointer.
- You have to make size information available to yourself some other
- way. I've added a few lines to your original program to suggest one
- way this can be done. Specifically, I added another array "sizes"
- that parallels the pointer array "record", in which the sizes of the
- strings are stored.
-
- >Ok, let see if with an example I could clarify what I'm trying to say,
-
- > char First_name[20];
- > char Last_name[20];
- > char Address[60];
- > char Phone[20];
- > char **ct, *cp;
- size_t *szp;
-
- > char *record[4];
- size_t sizes[4];
-
- > char ch;
- >
- > record[0] = First_name;
- sizes[0] = sizeof(First_name);
- > record[1] = Last_name;
- sizes[1] = sizeof(Last_name);
- > record[2] = Address;
- sizes[2] = sizeof(Address);
- > record[3] = Phone;
- sizes[3] = sizeof(Phone);
- > ct = record;
- > cp = *ct;
- szp = sizes;
-
- > while (!done) {
- > ch = getchar();
- > if (cp - *ct < sizeof(XXXXXXX)-1) {
- if (cp - *ct < *szp - 1)
- > *cp++ = ch;
- > } else {
- > beep();
- > }
- > }
-
- --
- Richard Krehbiel, Kastle Systems, Arlington VA USA
- rich@kastle.com (work) or richk@mnsinc.com (personal)
-
-